package com.czy.owner.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.TextingListModel;
import com.czy.owner.utils.MyLog;
import com.czy.owner.utils.StringUtils;
import com.czy.owner.utils.TimeUtils;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hedepu on 2017/10/31 0001.
 */
public class TestingListAdapter extends RecyclerArrayAdapter<TextingListModel> {

    private Context context;

    public TestingListAdapter(Context context) {
        super(context);
        this.context = context;
    }


    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new TestingListHolder(parent);
    }

    class TestingListHolder extends BaseViewHolder<TextingListModel> {


        @BindView(R.id.iv_texting_img)
        ImageView ivTextingImg;
        @BindView(R.id.tv_car_id)
        TextView tvCarId;
        @BindView(R.id.tv_car_type)
        TextView tvCarType;

        //        @BindView(R.id.linear_bottom)
//        LinearLayout linearBottom;

        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.linear_top)
        LinearLayout linearTop;
        @BindView(R.id.linear_bottom)
        LinearLayout linearBottom;

        @BindView(R.id.tv_error_string)
        TextView tvErrorString;
        @BindView(R.id.tv_distance)
        TextView tvDistance;
//        @BindView(R.id.tv_distance)
//        TextView tvDistance;

        public TestingListHolder(ViewGroup parent) {
            super(parent, R.layout.item_testing_list_recycler);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void setData(final TextingListModel data) {
            super.setData(data);
            tvCarId.setText(data.getLicenseNumber());
            tvCarType.setText(data.getChName());

            if (StringUtils.isEmpty(data.getAbnormalModel())) {
                linearBottom.setVisibility(View.GONE);
            } else {
                tvErrorString.setText(data.getAbnormalModel());

                linearBottom.setVisibility(View.VISIBLE);
            }

//            tvDistance.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
//            tvDistance.getPaint().setAntiAlias(true);//抗锯齿
            tvDistance.setText(data.getCurrentMileage() + "km");
            tvTime.setText(TimeUtils.timeStamp2Date(data.getEndTime(), "yyyy-MM-dd"));
            GlideUtils.loadImage(getContext(), data.getImageSrc(), ivTextingImg, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_icon, R.mipmap.default_icon);
        }
    }


}
